package com.emmy.walnut.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.emmy.walnut.constant.AppConstant;

public class PreferenceUtil {
    private static SharedPreferences sharedPreferences;
    private static SharedPreferences.Editor editor;

    static {
        sharedPreferences = AppConstant.APPLICATION_CONTEXT.getSharedPreferences(AppConstant.PRE_FILE_NAME,
                Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }

    public static void putBoolean(String key, boolean value){
        editor.putBoolean(key, value);
    }

    public static void putBooleanWithApply(String key, boolean value){
        editor.putBoolean(key, value).apply();
    }

    public static boolean getBoolean(String key){
        return sharedPreferences.getBoolean(key, false);
    }

    public static void putString(String key, String value){
        editor.putString(key, value);
    }

    public static void putStringWithApply(String key, String value){
        editor.putString(key, value).apply();
    }

    public static String getString(String key){
        return sharedPreferences.getString(key,"");
    }

    public static void putIntWithApply(String key, int value){
        editor.putInt(key, value).apply();
    }

    public static void putInt(String key ,int value){
        editor.putInt(key, value);
    }

    public static int getInt(String key){
        return sharedPreferences.getInt(key,0);
    }

    public static void remove(String key){
        editor.remove(key).apply();
    }

    public static void clear(){
        editor.clear().apply();
    }

    public static void apply(){
        editor.apply();
    }
}
